let ajaxTimes = 0; //发送网络请求的次数
// 这个是简写
// export const request = ()=>{}
export {
  request
}
const request = function request(params) {

  let header = {};
  if (params.url.includes("/my/")) {
    header["Authorization"] = uni.getStorageSync("token");
  }

  ajaxTimes++;
  uni.showLoading({
    title: "加载中",
    mask: true
  });
  // resolve 成功时的回调
  // reject 失败时的回调
  var res = new Promise(function(resolve, reject) {
    uni.request({
      ...params,
      header: header,
      success(success) {
        resolve(success)
      },
      fail(fail) {
        reject(fail)
      },
      complete: () => {
        ajaxTimes--;
        if (ajaxTimes === 0) {
          // 隐藏加载动画
          uni.hideLoading();
        }
      }
    });
  })
  return res
}
